module ziyi{
    export class basicui extends eui.Component{

        protected adata:any;
        public constructor(cd?: any) {
            super();

            if (typeof cd !== "undefined") {
                this.adata = cd;
            }

            const c_class = this["__class__"] as string;
            const c_arr = c_class.split(".");
            this.name = c_arr[1] || c_arr[0];

            this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.remove_self, this);
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
            this.addEventListener(eui.UIEvent.COMPLETE, this.mx_created, this);
        }

        //添加到舞台，然后绑定皮肤，然后初始化
        private onAddToStage() {
            this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
            this.set_skinname();
            if (!this.skinName) {
                this.pre_init();
            }
        }

        private mx_created(): void {
            this.removeEventListener(eui.UIEvent.COMPLETE, this.mx_created, this);
            this.pre_init();
        }

        protected remove_self() {
            const view = this;
            view.removeEventListener(egret.Event.ADDED_TO_STAGE, view.onAddToStage, view);
            view.removeEventListener(egret.Event.REMOVED_FROM_STAGE, view.remove_self, view);
            view.removeEventListener(eui.UIEvent.COMPLETE, view.mx_created, view);

            view.on_remove();
            view.removeChildren();
        }

        //通用的绑定皮肤方法，子类可覆盖
        protected set_skinname(): void {
            this.skinName = `../resource/eui_skins/${this.name}Skin.exml`;
        }

        //子类初始化操作
        protected pre_init(): void {
           
        }
        protected on_remove(): void { }//仅处理特殊逻辑操作aa
    }
}